# main.py
# FastAPI 主入口，包含应用初始化和路由引入
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from routers import user, card, shop, order
from utils import init_db

init_db()  # 启动时初始化数据库

app = FastAPI(title="卡牌交易系统")

# 允许前端跨域
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# 加载各功能路由
app.include_router(user.router)
app.include_router(card.router)
app.include_router(shop.router)
app.include_router(order.router)

@app.get("/")
def read_root():
    """健康检查接口"""
    return {"msg": "卡牌交易系统后端运行中"} 